<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
     <!-- <github-corner class="github-corner" />-->

      <!--<panel-group @handleSetLineChartData="handleSetLineChartData" />-->

      <el-row :gutter="32" style="padding-bottom: 32px">
        <el-col :xs="16" :sm="16" :lg="16">
          <el-card class="box-card myboxcard">
            <div slot="header" class="clearfix">
              <span>近7日生产趋势</span>
              <el-radio-group style="float: right; padding: 3px 0" v-model="productRadio"  size="mini" @change="setProductData">
                <el-radio-button label="cell">电芯</el-radio-button>
                <el-radio-button label="module">模组</el-radio-button>
                <el-radio-button label="pack">电池包</el-radio-button>
              </el-radio-group>
            </div>
            <line-chart :chart-data="lineChartData" />
          </el-card>
        </el-col>
        <el-col :xs="8" :sm="8" :lg="8">
          <el-card class="box-card myboxcard">
            <div slot="header" class="clearfix">
              <span>今日合格率</span>
              <el-radio-group style="float: right; padding: 3px 0" v-model="productRadio"  size="mini" @change="setProductData">
                <el-radio-button label="cell">电芯</el-radio-button>
                <el-radio-button label="module">模组</el-radio-button>
                <el-radio-button label="pack">电池包</el-radio-button>
              </el-radio-group>
            </div>
            <pie-chart :chart-data="pieChartData"/>
          </el-card>
        </el-col>
      </el-row>

      <el-row :gutter="32"  style="padding-bottom: 32px">
        <el-col :xs="24" :sm="24" :lg="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>正在进行的工单进度</span>
            </div>
            <ProgressChart :chart-data="progressChartData"/>
          </el-card>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>设备报警TOP5</span>
            </div>
            <RankingChart :chart-data="rankingChartData"/>
          </el-card>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <el-card class="box-card myboxcard">
            <div slot="header" class="clearfix">
              <span>今日不良分布</span>
              <el-radio-group style="float: right; padding: 3px 0" v-model="productRadio"  size="mini" @change="setProductData">
                <el-radio-button label="cell">电芯</el-radio-button>
                <el-radio-button label="module">模组</el-radio-button>
                <el-radio-button label="pack">电池包</el-radio-button>
              </el-radio-group>
            </div>
            <DysChart :chart-data="dysChartData"/>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import GithubCorner from '@/components/GithubCorner'
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/HomeLineChart'
import PieChart from './dashboard/HomePieChart'
import ProgressChart from './dashboard/HomeProgressChart'
import RankingChart from './dashboard/HomeRankingChart'
import DysChart from './dashboard/HomeDysChart'

const lineChartData = {
  cell: {
    ngData: [100, 120, 161, 134, 105, 160, 165],
    okData: [1200, 820, 910, 1540, 1620, 1400, 1450]
  },
  module: {
    ngData: [200, 192, 120, 144, 160, 130, 140],
    okData: [180, 160, 151, 106, 145, 150, 130]
  },
  pack: {
    ngData: [8, 10, 12, 10, 10, 9, 10],
    okData: [12, 9, 10, 13, 14, 13, 13]
  }
}

const pieChartData = {
  cell: [ { value: 1048, name: 'OK' }, { value: 735, name: 'NG' } ],
  module: [ { value: 108, name: 'OK' }, { value: 25, name: 'NG' } ],
  pack: [ { value: 10, name: 'OK' }, { value: 1, name: 'NG' } ]
}

const dysChartData = {
  cell: [
    { value: 320, name: 'OCV测试不良' },
    { value: 240, name: '裁剪不良' },
    { value: 149, name: '压平不良' },
    { value: 100, name: '电压不良' },
    { value: 59, name: '泡棉不良' }
  ],
  module: [
    { value: 120, name: '涂胶不良' },
    { value: 230, name: '刻码不良' },
    { value: 49, name: 'DCR测试不良' },
    { value: 10, name: '通讯不良' },
    { value: 29, name: '总电压不良' },
    { value: 19, name: '焊接不良' },
    { value: 5, name: '耐压不良' },
    { value: 119, name: '其他不良' }
  ],
  pack: [
    { value: 6, name: 'EOL测试不良' },
    { value: 2, name: 'DCR测试不良' },
    { value: 4, name: '耐压测试不了' },
    { value: 10, name: '其他不良' }
  ]
}

const progressChartData = [
      {
        name: '电池包工单',
        value: 100,
      },
      {
        name: '模组A工单',
        value: 20,
      },
      {
        name: '模组B工单',
        value: 82,
      }
    ]

const rankingChartData = {
  name:['EQCN001', 'EQCN002', 'EQCN003', 'EQCN004', 'EQCN005'],
  value:[28,16,12,8,3]
}

export default {
  name: 'Dashboard',
  components: {
    GithubCorner,
    PanelGroup,
    LineChart,
    PieChart,
    ProgressChart,
    RankingChart,
    DysChart
  },
  data() {
    return {
      productRadio: 'cell',
      lineChartData: lineChartData.cell,
      pieChartData: pieChartData.cell,
      progressChartData: progressChartData,
      rankingChartData: rankingChartData,
      dysChartData: dysChartData.cell
    }
  },
  methods: {
    setProductData(type){
      this.lineChartData = lineChartData[type]
      this.pieChartData = pieChartData[type]
      this.dysChartData = dysChartData[type]
    },
    handleSetLineChartData(type) {
      //this.lineChartData = lineChartData[type]
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .github-corner {
      position: absolute;
      top: 0;
      border: 0;
      right: 0;
    }

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }

  @media (max-width:1024px) {
    .chart-wrapper {
      padding: 8px;
    }
  }
</style>

<style type="text/css">
  .myboxcard .el-card__header{
    padding: 10px 20px;
  }
</style>
